package com.meme.editor.gui.level;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.FocusListener;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;

import javax.swing.JPanel;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.ListSelectionModel;

import java.util.List;
import java.util.Vector;

import com.meme.editor.EntityObject;
import com.meme.editor.level.define.*;
import com.meme.util.GuiUtil;


public class DefineFileSetupDialog extends JDialog 
             implements FocusListener, KeyListener, ListSelectionListener, MouseListener
{
	LevelMainView mLevelMainView;

	JTabbedPane mTabbedPanel;
	
	JList mTemplatesListControl;
	
	public DefineFileSetupDialog (LevelMainView levelMainView)
	{
		super ( GuiUtil.getTopFrame (levelMainView) );
		
		setTitle ("Define File Setup ...");

		
		setLevelMainView ( levelMainView );

		setMinimumSize (new Dimension (250, 200));
		setFocusable (true);
		addFocusListener (this);
		addKeyListener (this);	
		
		mTabbedPanel = new JTabbedPane ();
		mTabbedPanel.setTabPlacement (JTabbedPane.LEFT);
		add (mTabbedPanel);

		mTemplatesListControl = new JList ();
		mTemplatesListControl.setLayoutOrientation (JList.HORIZONTAL_WRAP);
		//mTemplatesListControl.setFixedCellWidth (80);	
		mTemplatesListControl.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
		mTemplatesListControl.addMouseListener (this);
		
	
	}
	
	public void setLevelMainView (LevelMainView view)
	{
		mLevelMainView = view;
	}
	
	
	public void setDefinefile (DefineFile defineFile)
	{
		mTabbedPanel.removeAll ();
		
		if (defineFile!= null)
		{
			// Tempaltes
			Vector<EntityObject> vectorTemplates = defineFile.getActorTemplateSet().getChildren();
			mTemplatesListControl.setListData (vectorTemplates);	
			mTabbedPanel.add ("Templates", new JScrollPane (mTemplatesListControl) );
		
			// ItemLists
			mTabbedPanel.add ("Item Lists", new JScrollPane (new JPanel()) );
			
			// Parameters
			mTabbedPanel.add ("Parameters", new JScrollPane (new JPanel()) );
		}
	}
	
	
//--------------------------------------------------------------------------
// as a KeyListener
//--------------------------------------------------------------------------

	  // Method descriptor #10 (Ljava/awt/event/KeyEvent;)V
	  public void keyTyped(java.awt.event.KeyEvent e)
	  {
		  
	  }
	  
	  // Method descriptor #10 (Ljava/awt/event/KeyEvent;)V
	  public void keyPressed(java.awt.event.KeyEvent e)
	  {
		  switch (e.getKeyCode())
		  {
		  default:
			  mLevelMainView.keyPressed (e);
		  }
	  }
	  
	  // Method descriptor #10 (Ljava/awt/event/KeyEvent;)V
	  public void keyReleased(java.awt.event.KeyEvent e)
	  {
		  
	  }

//--------------------------------------------------------------------------
// as a FocusListener
//--------------------------------------------------------------------------

	  
	// Method descriptor #9 (Ljava/awt/event/FocusEvent;)V
	public void focusGained(java.awt.event.FocusEvent e)
	{
	   return;
	}
  
    // Method descriptor #9 (Ljava/awt/event/FocusEvent;)V
    public void focusLost(java.awt.event.FocusEvent e)
    {
	   return;
    }	
  
	  
//--------------------------------------------------------------------------
// as a ListSelectionListener
//--------------------------------------------------------------------------

	@Override 
	public void valueChanged(ListSelectionEvent e) 
	{

	}
	  
	  
	public void mouseClicked(java.awt.event.MouseEvent e)
	{

	}
	  
	public void mousePressed(java.awt.event.MouseEvent e)
	{
		
	}
	  
	public void mouseReleased(java.awt.event.MouseEvent e)
	{
		if (e.getSource() == mTemplatesListControl)
		{
			//if (e.getClickCount() >= 2)
			if (e.getButton() == e.BUTTON1)
			{
				JList list = (JList) e.getSource();
				ActorTemplate template = (ActorTemplate) list.getSelectedValue();
				mLevelMainView.startCreatingNewActor (template);
			}
		}
	}
	  
	public void mouseEntered(java.awt.event.MouseEvent e)
	{
		
	}
	  
	public void mouseExited(java.awt.event.MouseEvent e)
	{
		
	}
}
